/**
 * Created by smp on 2017/6/6.
 */
var modelPath=ROOT_PATH+'/majorHazard/statisticsAnalysis/';

/**
 * 重新加载表格
 */
function reLoadData() {
    $('#dg1').datagrid('clearSelections');
    var queryParams1 = $('#tb1').serializeJson();
    var queryParams2 = $('#tb2').serializeJson();
    var queryParams = $.extend(queryParams1,queryParams2);
    $('#dg1').treegrid('options').queryParams = queryParams;
    $("#dg1").treegrid('reload');
}


function aja(year) {
    $('#dg1').treegrid({
        striped: true,
        idField:'id',
        treeField:'name',
        fit: true,
        singleSelect: true,
        fitColumns: true,
        toolbar: '#toolbar',
        url: modelPath + 'deviceLevelStatistics.shtml',
        queryParams:{
            year:year
        },
        columns: [[
            {field: 'name', title: '部门名称', width: 100},
            {field: 'level1', title: '一级', width: 80},
            {field: 'level2', title: '二级', width: 100},
            {field: 'level3', title: '三级', width: 100}
        ]]
    });

    $('#btn_clear').on("click", function () {
        $('#tb1').form('reset');
    });
    $('#btn_search').on("click", function () {
        reLoadData()
    });
}
$(function () {
    var year=new Date().getFullYear();
    var arr=[];
    for(var j=year-10;j<year+10;j++){
        var ob={};
        ob.id=j;
        ob.text=j;
        if(j==year)
            ob.selected=true;
        arr.push(ob);
    }

    $("#year").combobox({
        editable:false,
        data:arr,
        valueField:'id',
        textField:'text'
    });
    aja(year);
    $("#selectYear").click(function () {
        var ye=$("#year").combobox("getText");
        aja(ye);
    });
});